﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.SessionState;
using CustomsNuke.Scheduling.Jobs;
using Quartz;

namespace CustomsNuke.BusinessSystem
{
    public class Global1 : System.Web.HttpApplication
    {

        protected void Application_Start(object sender, EventArgs e)
        {

            JobKey mainJobKey = new JobKey("main", "Admin");

            if (Scheduling.Global.Current.Scheduler.CheckExists(mainJobKey))
            {
                Scheduling.Global.Current.Scheduler.ResumeJob(mainJobKey);
            }
            else
            {
                IJobDetail mainJob = JobBuilder.Create<MainJob>().WithIdentity(mainJobKey).Build();
                ITrigger trigger = TriggerBuilder.Create()
                                                .WithIdentity("main", "Admin")
                                                .WithSimpleSchedule(x => x.WithIntervalInMinutes(1).RepeatForever())
                                                .StartNow()
                                                .Build();
                Scheduling.Global.Current.Scheduler.ScheduleJob(mainJob, trigger);
            }
            Scheduling.Global.Current.Scheduler.Start();
        }

        protected void Session_Start(object sender, EventArgs e)
        {

        }

        protected void Application_BeginRequest(object sender, EventArgs e)
        {

        }

        protected void Application_AuthenticateRequest(object sender, EventArgs e)
        {

        }

        protected void Application_Error(object sender, EventArgs e)
        {

        }

        protected void Session_End(object sender, EventArgs e)
        {

        }

        protected void Application_End(object sender, EventArgs e)
        {
        }
    }
}